<?php
namespace app\index\controller;
use think\facade\View;
use think\facade\Db;
use think\facade\Request;
class warranty extends Base{
    public function __construct(\think\App $app) {
        parent::__construct($app);


    }    
    public function query(){
        $data = Request::param();
        if(!$data['keywords']){
            return json(['status'=>0,'msg'=>"请输入查询参数"]);
        }
        $r=Db::name("cms_warranty")->where("mobile|frame_number","=",$data['keywords'])->find();
        if(!$r){
            return json(['status'=>0,'msg'=>"未查询到质保信息"]);
        }else{
            $r['install_date_format']=date("Y-m-d",$r['install_date']);
            // 将时间戳增加质保年限
            $newTimestamp = strtotime('+'.$r['warranty_time'].' years', $r['install_date']);
            // 格式化新的时间戳，如果需要的话
            $r['warranty_time_end_format'] = date('Y-m-d', $newTimestamp);
            return json(['status'=>1,'msg'=>'查询成功','data'=>$r]);
        }
    }             
}